package org.procrastinationapp.web.pages.aaa;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.wicket.Request;
import org.apache.wicket.authentication.AuthenticatedWebApplication;
import org.apache.wicket.authentication.AuthenticatedWebSession;
import org.apache.wicket.authorization.strategies.role.Roles;

public class MyAuthenticatedWebSession extends AuthenticatedWebSession {
	private static List<String> ADMIN_LOGINS = new ArrayList<String>();
	static {
		ADMIN_LOGINS.add("bardaos");
		ADMIN_LOGINS.add("felipao");
	}

	private String userName;

	public String getUserName() {
		return userName;
	}

	public MyAuthenticatedWebSession(
			final AuthenticatedWebApplication application, Request request) {
		super(application, request);
	}
	
	@Override
	public boolean authenticate(final String username, final String password) {
		if (username.equals(password)) {
			this.userName = username;
			return true;
		}
		return false;
	}

	@Override
	public Roles getRoles() {
		if (isAdminUser()) {
			return new Roles(Roles.ADMIN + ", " + Roles.USER);
		}
		if (isSignedIn()) {
			return new Roles(Roles.USER);

		}
		return null;
	}

	public boolean isAdminUser() {
		return isSignedIn() && ADMIN_LOGINS.contains(userName);
	}
	
	/**
	 * TODO This wouldn't be necesary
	 */
	@Override
	public Locale getLocale(){
		return new Locale("es");
	}
}
